package net.realsee.controller.wcs.rcs.hik;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.realsee.common.utils.JsonUtils;
import net.realsee.domain.wcs.rcs.hik.HikRcsAgvCallback;
import net.realsee.domain.wcs.rcs.hik.HikRcsOperateResult;
import net.realsee.domain.wcs.rcs.hik.HikWarnReq;
import net.realsee.domain.wcs.rcs.hik.v4.HikRcsV4AgvCallback;
import net.realsee.service.wcs.rcs.hik.IHikService;
import net.realsee.service.wcs.rcs.hik.IHikV4Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 海康RCS回调入口
 *
 * @author 孙正华
 * @since 2023/8/18 10:00
 */
@SaIgnore
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/hik")
public class HikCallbackController {

    private final IHikService hikService;
    private final IHikV4Service hikV4Service;

    /**
     * 任务执行回调
     */
    @PostMapping("/agvCallback")
    public HikRcsOperateResult callback(@RequestBody HikRcsAgvCallback param) {
        log.info("[海康RCS][任务执行回调][开始]，参数={}", JsonUtils.toJsonString(param));
        HikRcsOperateResult result = hikService.callback(param);
        log.info("[海康RCS][任务执行回调][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

    /**
     * 告警推送
     */
    @PostMapping("/warnCallback")
    public HikRcsOperateResult warnCallback(@RequestBody HikWarnReq param) {
        log.info("[海康RCS][告警推送][开始]，参数={}", JsonUtils.toJsonString(param));
        HikRcsOperateResult result = hikService.warnCallback(param);
        log.info("[海康RCS][告警推送][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

    /**
     * 任务执行回调V4
     */
    @PostMapping("/v4/agvCallback")
    public HikRcsOperateResult agvCallbackV4(@RequestBody HikRcsV4AgvCallback param) {
        log.info("[海康RCS V4][任务执行回调][开始]，参数={}", JsonUtils.toJsonString(param));
        HikRcsOperateResult result = hikV4Service.callback(param);
        log.info("[海康RCS V4][任务执行回调][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

}
